package com.sproutcat.sample;

public class SingletonExample {

    public static volatile SingletonExample singleton;

    /**
     * 构造函数私有，禁止外部实例化
     */
    private SingletonExample() {
    }

    public static SingletonExample getInstance() {
        if (singleton == null) {
            synchronized (SingletonExample.class) {
                if (singleton == null) {
                    System.out.println("开始实例化对象");
                    singleton = new SingletonExample();
                }
            }
        }
        return singleton;
    }

    public static void main(String[] args) {
        SingletonExample.getInstance();
    }
}
